<!--论坛-->
<template>
  <div class="app-container">
    <div style="text-align:center">
    <h1>在线心理咨询平台互助论坛</h1>
    <p>交流心得体会，助力美好人生</p>
    </div>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item prop="dictName">
        <el-input
          v-model="queryParams.dictName"
          placeholder="请输入贴名"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table
      :data="typeList"
      style="width: 100%;margin-bottom: 20px;"
      row-key="id"
      default-expand-all
      :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
    >
      <el-table-column
        prop="title"
        label="贴名"
        sortable
      >
        <template slot-scope="scope">
          <div v-if="scope.row.title" style="margin-left: 10px;font-weight: bold;font-size: 18px">
            {{ scope.row.title }}
          </div>
          <div v-else style="flex: 1;margin-left: 100px">
            <el-avatar :src="scope.row.avatar"></el-avatar>
            <span style="font-size: 16px;font-weight: bold; text-align: left">
              {{ scope.row.name }}:<span style="font-weight: 400;font-size: 12px;color: #ccc;margin-left: 10px">{{ scope.row.content }}</span>
            </span>

          </div>
        </template>
      </el-table-column>
      <el-table-column
        prop="name"
        label="楼主名"
        sortable
        width="180"
      >
        <template slot-scope="scope">
          <div v-if="scope.row.title" style="margin-left: 10px;font-weight: bold;font-size: 18px">
            {{ scope.row.name }}
          </div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>

export default {
  name: 'Consult',
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      typeList: [{
        id: 1,
        title: '帖子1',
        name: '王小虎'
      }, {
        id: 2,
        title: '帖子2',
        name: '王小虎'
      }, {
        id: 3,
        title: '帖子3',
        name: '王小虎',
        children: [{
          id: 31,
          name: '张三',
          content: '回复内容1',
          avatar: 'https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png'
        }, {
          id: 32,
          name: '张三',
          content: '回复内容2',
          avatar: 'https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png'
        }]
      }, {
        id: 4,
        title: '帖子4',
        name: '王小虎'
      }],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        dictName: undefined,
        dictType: undefined,
        status: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      checkList: []
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = false
      /* this.loading = true;
      listType(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
          this.typeList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      ); */
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        dictId: undefined,
        dictName: undefined,
        dictType: undefined,
        status: '0',
        remark: undefined
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = []
      this.resetForm('queryForm')
      this.handleQuery()
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = '添加'
    },
    /** 修改按钮操作 */
    handleOnline(row) {
      this.reset()
      const dictId = row.dictId || this.ids
      /*  getType(dictId).then(response => {
         this.form = response.data;
         this.open = true;
         this.title = "修改";
       }); */
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          if (this.form.dictId != undefined) {
            /* updateType(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            }); */
          } else {
            /* addType(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            }); */
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleOffline(row) {
      const dictIds = row.dictId || this.ids
      this.$modal.confirm('是否确认删除编号为"' + dictIds + '"的数据项？').then(function() {
        //return delType(dictIds);
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess('删除成功')
      }).catch(() => {
      })
    }
  }
}
</script>
